﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/admin/Views/Shared/_Layout.cshtml";
    List<One_day.Models.Table> lst=(List<One_day.Models.Table>)ViewBag.lst;
}

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">商品管理</h1>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    当前所有商品
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                        <thead>
                            <tr>
                                <th>图片</th>
                                <th>商品名字</th>
                                <th>价格</th>
                                <th>已买</th>
                                <th>库存</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @{
                                foreach (var item in lst)
                                {
                                    <tr class="odd gradeX" id="row_@item.Id">
                                        <td><img src="/Upload/@item.PicUrl" style="width:20px;height:20px;" /></td>
                                        <td>@item.ProductName</td>
                                        <td>@item.Price</td>
                                        <td>@item.SelledAmount</td>
                                        <td>@item.StockAmount</td>
                                        <td>
                                            <button type="button" class="btn btn-primary" onclick="del(@item.Id)">删除</button>
                                            <a class="btn btn-primary" href="/admin/product/Update?id=@item.Id" >修改</a>
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
</div>

@section js{
    <script>
        function del(id) {
            var result = window.confirm("是否确认删除");//跳出用户确认对话框
            if (result) {
                $.ajax({
                    url: "/admin/product/delete",
                    async: true,
                    data: { id: id },
                    type: "post",
                    success: function (result) {
                        if (result.code == 100) {
                            $("#row_" + id).remove();
                        }
                        else {
                            window.alert(result.message);
                        }
                    }
                });
            }
        }
    </script>
    }

